﻿using System;

namespace IssueIT.Core.Domain.Model
{
	public class Tag : IEquatable<Tag>
	{
		public Tag(User postedBy, string text)
		{
			Text = text;
			CreatedBy = postedBy;
			CreatedAt = SystemTime.Now;
		}

		public string Text { get; private set; }
		public User CreatedBy { get; private set; }
		public DateTime CreatedAt { get; private set; }

		public bool Equals(Tag other)
		{
			if( ReferenceEquals(null, other) )
			{
				return false;
			}
			if( ReferenceEquals(this, other) )
			{
				return true;
			}
			return string.Equals(other.Text, Text, StringComparison.InvariantCultureIgnoreCase);
		}

		public override bool Equals(object obj)
		{
			return Equals(obj as Tag);
		}

		public override int GetHashCode()
		{
			return Text!=null ? Text.GetHashCode() : 0;
		}
	}
}